package com.chap17.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 * <code>Demo02</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-05-08 15:15
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class Demo02 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Runnable runnable = ()-> System.out.println("执行无返回结果的异步任务");
        CompletableFuture.runAsync(runnable);


        CompletableFuture<String> f = CompletableFuture.supplyAsync(() -> {
            System.out.println("执行有返回值的异步任务");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "Hello World";
        });

        System.out.println(f.get());

    }
}
